package com.lq.educationsystem.lqclasses.service.impl;

import com.lq.educationsystem.common.util.*;
import com.lq.educationsystem.common.vo.ClassesPageVo;
import com.lq.educationsystem.lqclasses.entiy.ClassesTb;
import com.lq.educationsystem.lqclasses.mapper.ClassesTbMapper;
import com.lq.educationsystem.lqclasses.service.ClassesBaseService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ClassesBaseImpl implements ClassesBaseService {
    @Autowired
    ClassesTbMapper classesTbMapper;
    @Override
    public void insertInfo(ClassesTb classesInfo) {

        System.out.println("要插入的数据为: "+classesInfo);
        int row = classesTbMapper.insert(classesInfo);
        System.out.println("Classes插入数据:"+row);
    }

    //通过数据删除
    @Override
    public void deleteById(Integer classesId) {
        int row = classesTbMapper.deleteByPrimaryKey(Long.valueOf(classesId));
        System.out.println("Classes删除数据:"+row);
    }

    @Override
    public void updateInfo(ClassesTb classesInfo) {
        int row = classesTbMapper.updateByPrimaryKeySelective(classesInfo);
        System.out.println("Classes删除数据:"+row);

    }

    @Override
    public Result<ClassesTb> queryById(Integer classesId) {


        ClassesTb classesInfo = classesTbMapper.selectByPrimaryKey(Long.valueOf(classesId));
        return ResultBuild.buildOk(new Result<ClassesTb>(),classesInfo);
    }

    @Override
    public ResultPage<ClassesTb> queryList(ClassesPageVo classesInfo) {
        //获取页数
        Integer page = classesInfo.getPage();
        Integer pageSize = classesInfo.getPageSize();
        //获取起始位置
        int start = PageUtil.getStart(page, pageSize);
        //数据复制
        ClassesTb classesTb = new ClassesTb();

        BeanUtils.copyProperties(classesInfo,classesTb);
        //查询语句
        List<ClassesTb>  classesTbs =classesTbMapper.queryList(start,pageSize,classesTb);

        int counts = classesTbMapper.queryCounts(classesTb);
        return ResultPageBuild.pageBuildOk(new ResultPage<ClassesTb>(),page,pageSize,counts,classesTbs);

    }

    @Override
    public ResultPage<ClassesTb> queryClassesInfoByClassesId(List<Integer> classesIdList) {

        List<ClassesTb> classesTbs= classesTbMapper.queryClassesInfoByClassesId(classesIdList);
        ResultPage<ClassesTb> resultPage = new ResultPage<>();
        resultPage.setData(classesTbs);
        return resultPage;
    }
}
